import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入表单名称',
    },
    fieldName: 'formName',
    label: '表单名称',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入描述说明',
    },
    fieldName: 'formDescription',
    label: '描述说明',
  },
  {
    component: 'Select',
    componentProps: {
      placeholder: '请选择发布状态',
      // 可选从DictEnum中获取 DictEnum.FORM_PUBLISH_STATUS 便于维护
      options: getDictOptions('form_publish_status'),
      // 下拉框搜索时 使用 label值搜索
      optionFilterProp: 'label',
    },
    fieldName: 'formPublishStatus',
    label: '发布状态',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入创建者',
    },
    fieldName: 'createBy',
    label: '创建者',
  },
  {
    component: 'RangePicker',
    componentProps: {
      showTime: false,
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
    fieldName: 'createTime',
    label: '创建时间',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  {
    align: 'center',
    type: 'checkbox',
    minWidth: 45,
    width: 45,
  },
  {
    title: '表单ID',
    field: 'formId',
    minWidth: 160,
    width: 160,
  },
  {
    title: '表单名称',
    field: 'formName',
    minWidth: 160,
  },
  {
    title: '描述说明',
    field: 'formDescription',
    minWidth: 160,
  },
  {
    title: '复制源ID',
    field: 'formSourceId',
    minWidth: 160,
  },
  {
    title: '创建者',
    field: 'createUserName',
    minWidth: 100,
  },
  {
    title: '创建时间',
    field: 'createTime',
    align: 'center',
    minWidth: 150,
    width: 150,
  },
  {
    title: '版本',
    field: 'formVersion',
    align: 'center',
    minWidth: 80,
    width: 80,
    slots: {
      default: ({ row }) => {
        return `V${row.formVersion}.0`;
      },
    },
  },
  {
    title: '状态',
    field: 'formPublishStatus',
    align: 'center',
    minWidth: 80,
    width: 80,
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.FORM_PUBLISH_STATUS 便于维护
        return renderDict(row.formPublishStatus, 'form_publish_status');
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    align: 'center',
    minWidth: 185,
    width: 185,
  },
];
